package com.rockcent.service.impl;

import com.rockcent.mall.lib.domain.MallFund;
import com.rockcent.mall.lib.domain.MallFundFlow;
import com.rockcent.mall.lib.domain.enumclass.FundTransactionFlow;
import com.rockcent.mall.lib.domain.enumclass.MallFundFlowTransactionType;
import com.rockcent.mall.lib.domain.enumclass.PaymentMethod;
import com.rockcent.mall.lib.repository.MallFundFlowRepository;
import com.rockcent.service.MallFundFlowSrv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * Created by zhangjh on 2017/4/5.
 */
@Service
public class MallFundFlowSrvImpl implements MallFundFlowSrv {

    @Autowired
    private MallFundFlowRepository mallFundFlowRepository;

    /**
     * @param mallFund
     * @param operationAmount
     * @param paymentMethod
     * @param seqNo
     * @param transactionFlow
     * @param transactionType
     */
    @Override
    public void save(MallFund mallFund, BigDecimal operationAmount, PaymentMethod paymentMethod, String seqNo, FundTransactionFlow transactionFlow, MallFundFlowTransactionType transactionType) {
        MallFundFlow mallFundFlow = new MallFundFlow();
        mallFundFlow.setAvailableAmount(mallFund.getAvailableAmount());
        mallFundFlow.setFrozen(mallFund.getFrozen());
        mallFundFlow.setMallFundId(mallFund.getId());
        mallFundFlow.setMallId(mallFund.getMallId());
        mallFundFlow.setMallOrderNum(seqNo);
        mallFundFlow.setMerchantOrderNum(seqNo);
        mallFundFlow.setOperationAmount(operationAmount);
        mallFundFlow.setTransactionFlow(transactionFlow);
        mallFundFlow.setPaymentMethod(paymentMethod);
        mallFundFlow.setTransactionType(transactionType);
        mallFundFlow = mallFundFlowRepository.save(mallFundFlow);
        mallFundFlow.setParentId(mallFundFlow.getId());
    }
}
